package com.atm.test;

import com.atm.pojo.User;
import com.atm.utill.MyConverter;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;

class Demo{
    private String name;
    private Date birthday;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}
public class beanutilsDemo {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        ConverterDemo();
    }
    public static void ConverterDemo() throws InvocationTargetException, IllegalAccessException {
        HashMap<String, Object> demoMap = new HashMap<>();
        demoMap.put("name","demo");
        demoMap.put("birthday","2000-01-30");
        Demo demo = new Demo();
        ConvertUtils.register(new MyConverter(), Date.class);
        BeanUtils.populate(demo,demoMap);
        System.out.println("demo = " + demo);
    }
    public static void test01() throws InvocationTargetException, IllegalAccessException {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("icon","6225123456788");
        stringObjectHashMap.put("name","zly");
        stringObjectHashMap.put("pwd","zly_123");
        stringObjectHashMap.put("mobile","13211112222");
        stringObjectHashMap.put("idcard","410102199001018978");
        stringObjectHashMap.put("balance",2000.00);
        User user = new User();
        BeanUtils.populate(user,stringObjectHashMap);
        System.out.println("user = " + user);
    }

}
